/*
 * license.h - CMDB License Control Module
 * Clunix, Yongjae Lee <yjlee@clunix.com>, 2000.10.17,2002.8.3.
 *
 * Copyright (c) 2000 by Clunix Inc. All Rights Reserved.
 *
 * 2001.1.9. Changed to license key system
 * 2002.8.2. Add hidden key
 * 2002.8.3. Send license info info
 */

#ifndef LICENSE_H
#define LICENSE_H

#define LICENSE_LEVEL_NONE  0
#define LICENSE_LEVEL_BASE  1
#define LICENSE_LEVEL_FULL  3

#define CRYPT_C1            183
#define CRYPT_C2            73

#define LICENSE_KEY_C1  77 
#define LICENSE_KEY_C2  301

#define NODE_LIMIT_SHIFT   5
#define EXPIRE_TIME_SHIFT  5

#define SHIFT_INT(val, s)  \
	(((unsigned int)(val) << (s)) | ((unsigned int)(val) >> (32 - (s))))
#define SHIFT_SHORT(val, s)  \
	(((unsigned short)(val) << (s)) | ((unsigned short)(val) >> (16 - (s))))

typedef struct {
	char product_symbol[5];
	char product_arch;
	short node_limit;
	int expire_time;
	short random_key;
} product_key_t;

int rand_mask(int mask);
void swap_bit(char *buf, int a, int b);
ECMBOOL get_license_value(char *license_key, int *product_arch, int *expire_time, int *node_limit);
int get_license_level(char *prefix);
char *get_license_level_str(int level);
void get_license_arch_str(int arch, char *arch_str_ret);

ECMBOOL license_check(void);  /* load license key and set limits */
int license_check_node(int node_num);
int license_check_expire(int cur_time_sec);
int license_get_level(void);

/* Level check macros */
#define IS_FULL_LEVEL  (license_get_level() == LICENSE_LEVEL_FULL)
#define IS_BASE_LEVEL  (license_get_level() == LICENSE_LEVEL_BASE)


/* Send license report information to central server; in license_rpt.c */
#if LICENSE_REPORT
void license_rpt_init(int cur_time_sec, char *key);
void license_rpt_check(int cur_time_sec);
#endif

#endif  /* LICENSE_H */

